import React, {Component} from 'react';
import {StyleSheet, Text, View, Image, 
  ImageBackground,TouchableOpacity,
  Dimensions,SafeAreaView,StatusBar
} from 'react-native';
import * as WeChat from 'react-native-wechat'
const {height, width} = Dimensions.get('window');
import DeviceStorage from '../common/DeviceStorage';
var timer;
export default  class Welcome extends Component{
  static navigationOptions = ({ navigation }) =>{
    return{
      header:null,
    }
  };
  constructor(props){
    super(props);
    this.state = ({
      time:3,
    })
		WeChat.registerApp('wx6a80c69414eb99bf');
  }
  componentDidMount(){
    //DeviceStorage.delete('user');
    // setTimeout(()=>{
    //   this.goHome();
    // },3000)
    timer = setInterval(()=>{
      if(this.state.time == 0){
        this.goHome();
        return;
      }
      this.setState({
        time:this.state.time-1,
      })
    }, 1000);
  }
  goHome(){
    clearInterval(timer);
    //console.log(this.props.navigation);
    const {navigation} = this.props;
    if(navigation){
      navigation.replace("home");
    }
  }
  render(){
    return(
      <SafeAreaView style={styles.container}>
        <StatusBar hidden={true} backgroundColor='black' /> 
        {/* <ImageBackground source={require('../images/login/welcome1.png')} style={{width: width, height: height}}>
          <View style={{flexDirection:'row',justifyContent:'flex-end',marginTop:20}}>
            <TouchableOpacity style={styles.topView} onPress={()=>this.goHome()}>
              <Text style={{color:'white'}}>点击跳过 {this.state.time}</Text>
            </TouchableOpacity>
          </View>
        </ImageBackground> */}
        <View style={{flex:1}}>
          <View style={{position:'absolute',flexDirection:'row',justifyContent:'flex-end',top:30,zIndex:9999,right:20}}>
            <TouchableOpacity style={styles.topView} onPress={()=>this.goHome()}>
              <Text style={{color:'white'}}>点击跳过 {this.state.time}</Text>
            </TouchableOpacity>
          </View>
          <Image source={require('../images/login/welcome1.gif')} 
         
            style={{width:width,height:height}} />
        </View>
        
      </SafeAreaView>
    )
  }
}
const styles = StyleSheet.create({
  topView:{
    backgroundColor:'rgba(0,0,0,0.2)',
    marginTop:5,
    marginRight:5,
    padding:5,
    borderRadius:3,
  },  
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
  },
})